/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package calculadorfpa.util;

import java.math.BigDecimal;

/**
 *
 * @author TECBMBKD
 */
public class FormatUtil {
    public static int parsePositiveInteger(String s) {
        
        int ret = Integer.parseInt(s);
        if(ret <= 0) {
            throw new NumberFormatException();
        }
        
        return ret;
    }
    
    public static int parseZeroPositiveInteger(String s) {
        
        int ret = Integer.parseInt(s);
        if(ret < 0) {
            throw new NumberFormatException();
        }
        
        return ret;
    }
    
    public static double parsePositiveDouble(String s) {
        
        double ret = Double.parseDouble(s.replace(",","."));
        if(ret <= 0) {
            throw new NumberFormatException();
        }
        
        return ret;
    }
    
    public static double arredondarValor(double d) {
        return new BigDecimal(d).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
    }
}
